package com.programmercarl.greed;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/assign-cookies/
 * 分发饼干 AC
 *
 * @author yulongtian
 * @create 2025-02-06 13:24
 */
public class Test01 {
    public static void main(String[] args) {
        Test01 test01 = new Test01();
        System.out.println(test01.findContentChildren(new int[]{1, 2}, new int[]{1, 2, 3}));
    }

    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int i = 0;
        int j = 0;
        int count = 0;
        while (i < g.length) {
            while (j < s.length && s[j] < g[i]) {
                j++;
            }
            if (j == s.length) {
                return count;
            }
            j++;
            i++;
            count++;
        }
        return count;
    }

}
